Usage of R Packages
For Windows OS
To install and use packages in R on a 64-bit Windows system, follow these steps:
1. Install Packages from CRAN
The Comprehensive R Archive Network (CRAN) hosts numerous R packages. To install a package from CRAN:
Open RStudio
Console.Use the
install.packages()function with the package name in quotes:install.packages("package_name")For example, to install the
ggplot2package:install.packages("ggplot2")If prompted, select a CRAN mirror close to your location.
2. Install Packages from Bioconductor
Bioconductor provides packages for bioinformatics. To install packages from Bioconductor:
Install the BiocManager package if not already installed:
install.packages("BiocManager")Use
BiocManager::install()to install the desired package:BiocManager::install("package_name")For example, to install the
limmapackage:BiocManager::install("limma")
3. Install Packages from GitHub
Some packages are hosted on GitHub. To install them:
Install the
devtoolspackage if not already installed:install.packages("devtools")Use
devtools::install_github()with the repository name:devtools::install_github("username/repository")For example, to install the
ggplot2package from its GitHub repository:devtools::install_github("tidyverse/ggplot2")
4. Load Installed Packages
After installation, load a package into your R session using the library() function:
library(package_name)For example, to load the ggplot2 package:
library(ggplot2)Once loaded, you can access the functions and datasets provided by the package.
5. Verify Package Installation
To confirm that a package is installed:
Use the
installed.packages()function:installed_packages <- installed.packages() "package_name" %in% rownames(installed_packages)This returns
TRUEif the package is installed, otherwiseFALSE.
6. Update Installed Packages
Regularly update packages to incorporate improvements and bug fixes:
To update all installed packages:
update.packages()To update a specific package:
install.packages("package_name")
7. Remove Installed Packages
To uninstall a package:
remove.packages("package_name")For example, to remove the ggplot2 package:
remove.packages("ggplot2")By following these steps, you can effectively manage R packages on your Windows system.
For macOS
Installing R packages in macOS is strikingly similar to Windows systems.
What’s Next?
Go back to Starting Page
Go back to Installation Guide
Proceed to Required Packages for Training
Jump to Installing Git Version Control